package com.learning.datastruct.collection.queue;

import com.learning.datastruct.heap.MyBinaryHeap;
import java.util.Comparator;

/**
 * 优先队列 使用二叉堆来实现
 */
public class MyPriorityQueue<E> extends MyQueue<E> {
    private MyBinaryHeap<E> heap;

    public MyPriorityQueue(Comparator<E> comparator) {
        heap = new MyBinaryHeap<>(comparator);
    }

    public MyPriorityQueue() {
        this(null);
    }

    @Override
    public int size() {
        return heap.size();
    }

    @Override
    public boolean isEmpty() {
        return heap.isEmpty();
    }

    @Override
    public void clear() {
        heap.clear();
    }

    @Override
    public void offer(E element) {
        heap.add(element);
    }

    @Override
    public E poll() {
        return heap.remove();
    }

    @Override
    public E peek() {
        return heap.get();
    }
}
